package api

import (
	"gitee.com/dehow/k8sdev/db"
	"gitee.com/dehow/k8sdev/model"
	"gitee.com/dehow/k8sdev/remote_service"
	"github.com/gin-gonic/gin"
	"net/http"
)

type OrderApi struct {
}

func NewOrderApi(c *gin.Context) OrderApi {
	a := OrderApi{}
	return a
}

func (api OrderApi) GetOrderInfo(c *gin.Context) {
	orderNum, _ := c.GetQuery("order_num")
	order := model.Order{}
	err := db.GetDbOrder().Where("order_num=?", orderNum).First(&order).Error
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    "FAIL",
			"message": err.Error(),
		})
		return
	}
	cusCli := remote_service.Customer{}
	ret, errH := cusCli.CustomerInfo(order.UserName)
	if errH != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    "FAIL",
			"message": errH.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    "SUCCESS",
		"message": "成功",
		"data":    map[string]any{"order": order, "customer": ret},
	})
}
